home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 9671 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.4 KB

  1. Path: news.umbc.edu!not-for-mail
  2. From: schlein@umbc.edu (Jonas J. Schlein)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: confusion between putchar and printf
  5. Date: 12 Mar 1996 13:27:15 -0500
  6. Organization: University of Maryland Baltimore County
  7. Message-ID: <4i4fm3$7ht@umbc9.umbc.edu>
  8. References: <4i1v2n$30o@news.azstarnet.com>
  9. NNTP-Posting-Host: umbc9.umbc.edu
  10. NNTP-Posting-User: schlein
  11.  
  12. Howard Salmon  <captarm@azstarnet.com> wrote:
  13. |> K & R (section 1.5) states that "putchar(c) prints the contents of the 
  14. |> integer variable c as a character, usually on the screen".
  15. |> 
  16. |> Here's a small program that I wrote testing putchar.  Why doesn't it 
  17. |> compile?
  18.  
  19. Usually a tad of common sense helps, but here's the main problem.
  20. The putchar() function prints a single character while the printf()
  21. function is more of a general purpose printing function that can
  22. do lots of stuff depending on what you tell it.
  23.  
  24. |> #include <stdio.h>
  25. |> # define A "hello world!"
  26.  
  27. 'A' is a string.
  28.  
  29. |> main()
  30. |> {
  31. |>     int c;
  32. |>     c =  A;
  33.  
  34. 'c' is an int which cannot store a string.
  35.  
  36. |>     putchar(A);
  37.  
  38. 'A' is a string which putchar() is unable to print.
  39.  
  40. |> }
  41. |> 
  42. |> Thanks, 
  43.  
  44. Just say what you are trying to do. Do you want to print the string or
  45. perhaps just the first character in the string? What errors did your
  46. compiler give you...Most likely these identifies the line(s) the problems
  47. were on.
  48. -- 
  49. "If it wasn't for C, we would be using BASI, PASAL, and OBOL."
  50.  
  51. Jonas J. Schlein  (schlein@gl.umbc.edu)
  52.